package com.gxan.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gxan.common.R;
import com.gxan.pojo.House;
import com.gxan.service.HouseService;
import com.gxan.service.impl.HouseServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateHouse")
public class UpdateHouseServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        String community_id = request.getParameterValues("community_id")[0];
        String dong_id = request.getParameter("dong_id");
        String house_name = request.getParameter("house_name");
        String huzhu_name = request.getParameter("huzhu_name");
        String huzhu_tel = request.getParameter("huzhu_tel");
        String house_depart = request.getParameter("house_depart");
        //把数据封装House对象
        House house = new House();
        house.setId(Integer.parseInt(id));
        house.setCommunity_id(Integer.parseInt(community_id));
        house.setDong_id(Integer.parseInt(dong_id));
        house.setHouse_name(house_name);
        house.setHuzhu_name(huzhu_name);
        house.setHuzhu_tel(huzhu_tel);
        house.setHouse_depart(Integer.parseInt(house_depart));

        //调用service
        HouseService houseService = new HouseServiceImpl();
        R r = houseService.updateHouse(house);
        //回写响应
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JSONObject.toJSONString(r));

    }
}
